﻿@{
    ViewData["Title"] = "客户填写";
}
<form role="form" class="form-horizontal">
    <!--客户信息-->
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">CARD #<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_orderNO">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">EXPIRATION DATE<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_BuyWay">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name">CVV<em style="color: red;">*</em></label>
        <div class="col-sm-5">
            <input type="text" class="form-control" id="txt_ReferralNo">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="name"></label>
        <div class="col-sm-5">
            <button type="button" onclick="Save()" class="btn btn-primary">保存</button>
        </div>
    </div>
</form>
@section Scripts{
    <script type="text/javascript">
        function getQueryString(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            let r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURIComponent(r[2]);
            };
            return null;
        }

        $(function () {
            Initia();
        });

        //初始化数据
        function Initia() {
            $.ajax({
                url: "http://106.15.9.236:40580/api/app/order/" + getQueryString("orderId"),
                contentType: "application/json-patch+json",
                type: "GET",
                dataType: "json",
                success: function (data) {
                    if (data) {
                        $("#txt_bsapi").val(data.bsapi);
                        $("#txt_posapi").val(data.posapi);
                        $("#txt_authCenterHost").val(data.authCenterHost);
                        $("#txt_bsPageHost").val(data.bsPageHost);
                        $("#txt_posPageHost").val(data.posPageHost);
                    }
                },
                error: function () {
                    alert("服务不可用，请联系管理员");
                }
            })
        }

        //保存
        function Save() {
            var orderNo = $("#txt_orderNO").val().trim();
            var buyWay = $("#txt_BuyWay").val().trim();
            var referralNo = $("#txt_ReferralNo").val().trim();

            var ParamData = {
                orderNo: orderNo,
                buyWay: buyWay,
                referralNo: referralNo
            };

            $.ajax({
                url: "http://106.15.9.236:40580/api/app/order",
                contentType: "application/json-patch+json",
                type: "POST",
                data: JSON.stringify(ParamData),
                dataType: "json",
                success: function (data) {
                    alert("保存成功！" + data.id);
                    window.location.href = 'http://106.15.9.236:40580/api/app/pdf/exportOrder/"+ getQueryString("orderId");
                },
                error: function (data) {
                    alert("保存失败！\r\n" + data.responseJSON.error.message);
                }
            })
        };

    </script>
}